package com.yunshipei.ui.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.View;

import com.yunshipei.common.wedigt.YspTitleBar;
import com.yunshipei.enterplorer.R;
import com.yunshipei.model.MainExtraBean;

import butterknife.Bind;

public class PadCommonTitleFragment extends BaseBodyFragment {

    public static final String ARGS_TITLE = "args.title";
    public static final String ARGS_TARGT_FRAGMENT_NAME = "args.target.fragment.name";

    public static PadCommonTitleFragment newInstance(MainExtraBean mainExtraBean, String title, String targetFragmentName) {
        PadCommonTitleFragment padCommonTitleFragment = new PadCommonTitleFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable(ARGS_CUSTOMER_MAIN_DATA, mainExtraBean);
        bundle.putString(ARGS_TITLE, title);
        bundle.putString(ARGS_TARGT_FRAGMENT_NAME, targetFragmentName);
        padCommonTitleFragment.setArguments(bundle);
        return padCommonTitleFragment;
    }

    @Bind(R.id.title_bar)
    protected YspTitleBar titleBar;

    private String title;
    private String targetFragmentName;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        title = getArguments().getString(ARGS_TITLE);
        targetFragmentName = getArguments().getString(ARGS_TARGT_FRAGMENT_NAME);
    }

    @Override
    public int viewLayout() {
        return R.layout.fragment_pad_common_title;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        titleBar.setTitle(title);
        if (!TextUtils.isEmpty(targetFragmentName)) {
            Fragment fragment = getChildFragmentManager().findFragmentByTag(targetFragmentName);
            if (fragment == null) {

            }
        } else {
            throw new RuntimeException("Illegal call,need target fragment name...");
        }
    }

    private Fragment getTargetFragment(String targetFragmentName) {
        if (targetFragmentName.equals(SettingsFragment.class.getName())) {
            return SettingsFragment.newInstance(mMainExtraBean);
        } else if (targetFragmentName.equals(AboutFragment.class.getName())) {
            return AboutFragment.newInstance(mMainExtraBean);
        }
        return null;
    }
}
